home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue26 / chessbrd / CHESSBRD.ZIP / PAS / CHESSBRD.TXT < prev   
Encoding:
Text File  |  1997-09-08  |  12.7 KB  |  321 lines

  1. ---------------------------------------------------------------------------
  2. Welcome to the Chessboard component v1.0 for Delphi 2, Delphi 3 and
  3. Borland C++ Builder !
  4.  
  5. version 1.11 - July 25th 1997
  6. ---------------------------------------------------------------------------
  7. Description:
  8.  
  9. The Chessboard component provides a customizable 2D Chessboard
  10. that can keep track of a game and verify the legality of moves.
  11. It allows the programmer to trap  the following events:
  12.  
  13. LegalMove, Illegal Move, Capture, En Passant, Castling, Promotion,
  14. Check, Mate, Stale Mate and Only Two Kings Left.
  15.  
  16. The colors, size, Pieces and Squares can be customized. The component
  17. can be resized at runtime.
  18.  
  19. The Chessboard component comes with three files:
  20. Chess.cpp (source file), Chess.h (header file) and Chess.txt
  21. (current file).
  22.  
  23. ---------------------------------------------------------------------------
  24. Installation of the component:
  25.  
  26. Start Delphi2, Delphi3 or Borland C++ Builder.
  27. Select "Component", "Install" ,"Add" and
  28. "Browse" and then browse to the file CHESS.PAS. The component will
  29. appear on a new tab called Chess.
  30. Note: Borland C++ Builder users can also choose for CHESS.CPP
  31. ---------------------------------------------------------------------------
  32. Product History:
  33.  
  34. version 1.11 - July 25th 1997
  35.       * Small bug in PAS file did not allow compiling of the component.
  36. version 1.1 - July 23th 1997
  37.       * Fixed bug: Pieces were not displayed properly when being dragged
  38.         if the Chessboard were not the child of the form
  39.       * Fixed bug: The letters A-H were not displayed in the right position
  40.         if WhiteOnTop were TRUE
  41.       * Removed property Align because it was put there without the
  42.         intention.
  43.       * Added property Enabled, which allows to lock the Chessboard
  44.       * Added member function DrawChessPiece which allows displaying
  45.         of a chess piece outside of the component.
  46.       * Datatype Square is now being used consequently
  47.  
  48. version 1.0 - June 20th 1997
  49.       * Added PAS file for Delphi2 and Delphi3
  50. version 1.0 - June 11th 1997
  51.       * initial version (C++ Builder only)
  52. ----------------------------------------------------------------------------
  53.  
  54. Property Descriptions:
  55.  
  56. Boardlines: Boolean
  57.      Determines whether lines will be drawn
  58.      around the board and between the squares
  59.  
  60. BorderBitmap: TBitmap
  61.      If assigned a value, this bitmap will be used to draw the border around
  62.      the board. BorderColor will then be ignored.
  63.  
  64. BorderColor: TColor
  65.     Sets the color of the border. Will be visible only if no value has
  66.     been assigned to BorderBitmap.
  67.  
  68. CastlingAllowed: CastleSet
  69.      This set stores whether castling is still allowed for each king in each
  70.      direction. Example: CastleSet<<WhiteKingSide will allow short castling
  71.      for white while CastleSet>>BlackQueenSide will disable long castling
  72.      for Black.
  73.  
  74. CoordFont: TFont
  75.     Sets the font eventually used to display the coordinates around the board.
  76.  
  77. CurrentMove: Integer
  78.      Stores the current move of the game in the list. CurrentMove cannot be
  79.      modified directly. Use:  GotoMove (int move, bool WhiteMoves);
  80.      to change its value.
  81.  
  82. CustomPieceSet: TBitmap
  83.      If assigned a legal value (that is a bitmap with a Width of
  84.      1.5 times its Height) this bitmap will be used as the new piece set
  85.      instead of the default The bitmap should consist of 6 x 4 smaller square
  86.      bitmaps of equal size. The order of the pieces should be: pawn, knight,
  87.      bishop, rook, queen and king. The first row represents the white pieces,
  88.      the third row represents the black pieces. The second and fourth row
  89.      should be monochrome and will be used to determine the mask of the white
  90.      and black pieces respectively. The pieces will not be shown in the place
  91.      where the mask bitmap contains a non-zero value. This allows transparent
  92.      drawing of the pieces on the board.
  93.  
  94. DisplayCoords: CoordSet
  95.      Determines whether coordinates are being displayed around the screen.
  96.      Examples: DisplayCoords<<West will display coordinates on the left of
  97.      the board. DisplayCoords>>East will make disappear coordinates at the
  98.      right of the board.
  99.  
  100. EnPassant: Square
  101.      if EnPassant doesn't equal None, it contains the square on which
  102.      an EnPassant capture can take place. If white moves for instance
  103.      E2-E4, EnPassant will be set to the value E3 (on which the pawn
  104.      can be taken).  Legal values are: A3-H3, A6-H6
  105.  
  106. LineStyle: TPen
  107.      Contains the linestyle eventually used to display lines between
  108.      the squares and around the board.
  109.  
  110. Position: String
  111.      The contents of the board are stored in this string which is
  112.      always 64 characters long. The board is stored from square
  113.      A8 through H8 to H1. Each character represents a piece on the
  114.      board. The characters P, N, B, R, Q, K represent the pawn
  115.      knight, bishop, rook, queen and king respectively.
  116.      White pieces are uppercased, black pieces lowercased. Empty
  117.      squares are represented by spaces.
  118.      To quickly initialize a standard setup, fill the string
  119.      with 'init'.
  120.  
  121. Resizable: Boolean
  122.      Determines whether the ChessBoard can be resized. If TRUE,
  123.      when the user moves the cursor over the right-down corner,
  124.      the shape of the cursor will change and allow the ChessBoard
  125.      to be resized. The resizing does not yet happen flicker-free.
  126.  
  127. ResizeMinSize: Integer
  128.      The minimum allowed size of the ChessBoard (it's Width and Height)
  129.      while it is in the resizing state.
  130.  
  131. ResizeMaxSize: Integer
  132.      The maximum allowed size of the ChessBoard (it's Width and Height)
  133.      while it is in the resizing state.
  134.  
  135. SizeOfBorder: Integer
  136.      Determines the width of the border around the board. Changing its
  137.      value may change the size of the chessboard as well. (Width and Height)
  138.  
  139. SizeOfSquare: Integer
  140.      Determines the squaresize. Changing its value may change the size of
  141.      the chessboard as well. (Width and Height)
  142.  
  143. SquareColorDark: TColor
  144.     The color of the dark squares. Will be visible only if no value has
  145.     been assigned to SquareDark.
  146.  
  147. SquareColorLight: TColor
  148.     The color of the light squares. Will be visible only if no value has
  149.     been assigned to SquareLight.
  150.  
  151. SquareDark: TBitmap
  152.      If assigned a value, this bitmap will be used to draw the border around
  153.      the board to display the dark squares. SquareColorDark will then be
  154.      ignored.
  155.  
  156. SquareLight: TBitmap
  157.      If assigned a value, this bitmap will be used to display the light
  158.      squares. SquareColorLight will then be ignored.
  159.  
  160. StandardSize: StandardSet
  161.     Sets the size of the standard pieceset. The standard pieceset will
  162.     only be used if no value has been assigned to CustomPieceSet.
  163.     Legal values are: size32, size40, size64 and size80
  164.  
  165. WhiteOnTop: Boolean
  166.      Controls whether the white pieces are being
  167.      displayed on top of the board. Use: WhiteOnTop=!WhiteOnTop to flip the
  168.      board.
  169.  
  170. WhiteToMove: Boolean
  171.      Readonly. Sets the turn to white if TRUE and to black if FALSE;
  172.  
  173. ---------------------------------------------------------------------------
  174. Methods of the Public Interface:
  175.  
  176. -Pieces can contain the following (char) values:
  177.  p,b,n,r,q or k for a black pawn, knight bishop, rook queen or king
  178.  P,B,N,R,Q or K for a white pawn, knight bishop, rook queen or king
  179.  
  180. function BlackInCheckAfter(oldsq, newsq: Square): Boolean
  181.        returns TRUE if black is in check after the indicated move
  182.  
  183. function ClearSquare(sq: Square): Boolean
  184.        will empty the square with number sqn
  185.  
  186. function ColorOfPiece (piece: Char): Integer
  187.        returns BLACK (0) or WHITE  (1) if piece is a legal piece
  188.        otherwise NOPIECE (-1)
  189.  
  190. function ColorOfSquare (sq: Square): Integer
  191.        returns BLACK or WHITE according to the color of square sqno.
  192.  
  193. procedure DrawChessPiece (canvas: TCanvas; x,y: Integer; piece: Char)
  194.        Draws the Chess piece, indicated by 'piece'  on the given canvas,
  195.        at the given offset (x,y).
  196.        This method uses some kind of MaskBlt, and draws only in the place
  197.        where the mask has its bits set so drawing on a patterned surface
  198.        is possible.
  199.  
  200. function GetMove (moveno: Integer; whiteMoves: Boolean): MoveInfo
  201.        Returns a MoveInfo structure filled with the information
  202.        about the indicated move. Returns a structure with all
  203.        zero values and an initial position in the case the
  204.        move could not be found in the movelist.
  205.  
  206. function GetMoveList: TStringList
  207.        Returns a TStringList with all the moves of the current game.
  208.  
  209. function GotoMove (moveno: Integer; whiteMoves:Boolean): Boolean
  210.        Jump to the indicated move in the game and
  211.        set the position accordingly. Returns FALSE if
  212.        the move cannot be found in the movelist.
  213.  
  214. function LegalMoveAvailable: Boolean;
  215.        Returns TRUE if a move can be made from the current position.
  216.  
  217. function MouseToSquare (x, y: Integer): Square;
  218.        converts coordinates to a square value.
  219.        For instance CoordsToSquare (1,4) will return A4.
  220.  
  221. function Move (oldsq, newsq: Square): Boolean
  222.        will make a move and return TRUE if the move is legal.
  223.        The move will be both displayed on the board and registered in
  224.        memory. For castling: pass the move of the king.
  225.        Example: Move (E2,E4)
  226.  
  227. function MoveBackward: Boolean
  228.        Moves backward in the list of played moves and sets the position
  229.        accordingly. Returns FALSE if there's no move available.
  230.  
  231. function MoveForward: Boolean
  232.        Moves forward in the list of played moves and sets the position
  233.        accordingly. Returns FALSE if there's no move available.
  234.  
  235. procedure NewGame
  236.        Resets the position to the initial state.
  237.  
  238. function SetUpPosition (pos: MoveInfo; moveno: Integer; whiteMoves:Boolean): Boolean
  239.        Sets up the ChessBoard according to a given position. The first
  240.        move in the game will be moveno.
  241.  
  242. procedure UpdateChessBoard (char *oldpos);
  243.        Ensures all pieces are displayed on the right position.
  244.        Can be used if you change property Position manually.
  245.  
  246. function WhiteInCheckAfter(oldsq, newsq: Square):Boolean
  247.        returns TRUE if white is in check after the indicated move
  248.  
  249. function WindowToSquare (x, y: Integer): Square
  250.        returns the square at the position of (x,y).
  251.        x and y must be relative to the current window.
  252.  
  253. function XPos (sq: Square): Integer
  254.        returns the x-Coordinate (as an integer number in the range 1-8)
  255.        of the square.
  256.  
  257. function YPos (sq: Square): Integer
  258.        returns the x-Coordinate (as an integer number in the range 1-8)
  259.        of the square.
  260.  
  261. ---------------------------------------------------------------------------
  262. Event Handlers:
  263.  
  264. procedure Capture (Sender: TObject;oldSq,newSq: Square;CapturedPiece:Char)
  265.  
  266. procedure Castle (Sender: TObject;oldSq,newSq: Square)
  267.  
  268. procedure Check (Sender: TObject; oldSq, newSq: Square)
  269.  
  270. procedure Click; override
  271.  
  272. procedure DragCanceled; override;
  273.  
  274. procedure DragDrop(Source: TObject;X,Y: Integer);override
  275.  
  276. procedure DragOver(Source: TObject;X,Y: Integer; State: TDragState;var Accept: Boolean );override
  277.  
  278. procedure EndDrag(drop:Boolean)
  279.  
  280. procedure IllegalMove (Sender:TObject; sq: Square)
  281.  
  282. procedure LegalMove (Sender:TObject;oldSq,newSq: Square)
  283.  
  284. procedure Mate (Sender:TObject;     oldSq,newSq: Square)
  285.  
  286. procedure MouseDown(Button:TMouseButton; Shift:TShiftState;X,Y: Integer); override
  287.  
  288. procedure MouseMove(Shift:TShiftState; X,Y: Integer); override
  289.  
  290. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer);override
  291.  
  292. procedure OnlyTwoKingsLeft (Sender:TObject)
  293.  
  294. procedure Paint; override
  295.  
  296. procedure Promotion (Sender: TObject;oldSq,newSq: Square; var NewPiece: Char)
  297.       Note: you can choose your piece by assigning a new value to NewPiece.
  298.  
  299. procedure StaleMate (Sender: TObject; oldSq,newSq: Square)
  300.  
  301. ------------------------------------------------------------------------------
  302. Copyright, Liability and Author:
  303.  
  304. The Chessboard component may be freely used and distributed by anyone.
  305. The author does not accept liability for the software in any way.
  306.  
  307. Note that the standard pieceset that's being used comes straight out of
  308. Fritz4 for I thought I would never be able to design such clear and charming
  309. pieces. So take care not to break any laws with copyrighted material.
  310. If you would like to receive some Chess pieces from some other popular
  311. Chess programs, just drop me a line, which you can do as well if you
  312. have any bug reports, comments, suggestions, or wanted features:
  313.  
  314. Daniel Terhell
  315. Amsterdam
  316. Tel: +31 20 4866128
  317. kr8m8pr8@compuserve.com
  318. http://ourworld.compuserve.com/homepages/kr8m8pr8
  319. ------------------------------------------------------------------------------
  320.  
  321.